<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\DbConnection\Model\Model;
/**
 */
class ComplaintRecordLog extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'complaint_record_log';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'user_id', 'to_user_id', 'label', 'content','images','level'
    ];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [];

    /**
     * 新增投诉
     * @param int $user_id
     * @param int $to_user_id
     * @param string $label
     * @param string $content
     * @param array $images
     * @param int $level
     * @return ComplainRecordLog|\Hyperf\Database\Model\Model
     */
    public static function addRecord(int $user_id,int $to_user_id,array  $label,string $content,array $images,int $level)
    {
        return self::create([
            'user_id'       =>$user_id,
            'to_user_id'    => $to_user_id,
            'label'         => !empty($label) ? json_encode($label) : '',
            'content'       => $content,
            'images'        => !empty($images) ? json_encode($images) : '',
            'level'         => $level
        ]);
    }

    /**
     * 获取用户被投诉的记录
     * @param int $to_user_id
     * @return array
     */
    public static function getRecord(int $to_user_id)
    {
       return self::where('to_user_id',$to_user_id)->get()->toArray();
    }
}